package com.vayne.common;

import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

/**
 * @author xuerui.zhang
 * @since 2019-07-10 23:45
 */
public abstract class AbstractProducer {

    public static final String DEFAULT_BROKER_LIST = "localhost:9092";

    public static Properties initConfig(String brokerList) {
        Properties props = new Properties();
        if (brokerList == null) {
            props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, DEFAULT_BROKER_LIST);
        } else {
            props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
        }
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.put(ProducerConfig.RETRIES_CONFIG, "3");
        return props;
    }

}
